package coop.bancocredicoop.proyectos.gd;

import java.io.IOException;
import java.util.Properties;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import coop.bancocredicoop.proyectos.gd.alfresco.AlfrescoConfig;
import coop.bancocredicoop.proyectos.gd.alfresco.Utils;

public class GDConfig {

	private static Properties properties;
	private static final Log log = LogFactory.getLog(GDConfig.class);	
	
	static {
		String configFileName = "gd-config.properties";
		properties = new Properties();
        try {
			properties.load(Utils.class.getClassLoader().getResourceAsStream(configFileName));
			log.info(configFileName + " file loaded");
		} catch (IOException e) {
			log.error(String.format("Error loading %s file", configFileName), e);
		}	
	}
	
	public GrupoDocumentalIIConfig getGrupoDocumentalIIConfig() {
		return new GrupoDocumentalIIConfig(properties.getProperty("grupoDocumental2.repositoryPath"));
	}
	
	public AlfrescoConfig getAlfrescoConfig() throws IOException {
        return new AlfrescoConfig(properties.getProperty("alfresco.baseURL"),
        						  properties.getProperty("alfresco.serviceURL"),
        						  properties.getProperty("alfresco.rootPath"), 
        						  properties.getProperty("alfresco.credentials.user"),
        						  properties.getProperty("alfresco.credentials.password"));
	}
	
	public MailConfig getMailConfig() throws IOException {
		return new MailConfig(properties.getProperty("mail.host"));
	}
	
	public boolean useCrecerXXIMock() {		
		String useMockString = properties.getProperty("coop.bancocredicoop.proyectos.gd.crecerxxi.useMock", "false");
		return Boolean.parseBoolean(useMockString);
	}

	public boolean useRBACMock() {
		String useMockString = properties.getProperty("coop.bancocredicoop.proyectos.gd.rbac.useMock", "false");
		return Boolean.parseBoolean(useMockString);
	}
	
}
